from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-14 14:02:18.580121
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 14, Mar, 2022
Time: 14:02:23
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.5205
Nobs: 595.000 HQIC: -48.9258
Log likelihood: 7123.91 FPE: 4.36066e-22
AIC: -49.1843 Det(Omega_mle): 3.75324e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.349066 0.066990 5.211 0.000
L1.Burgenland 0.108306 0.040808 2.654 0.008
L1.Kärnten -0.110661 0.021320 -5.190 0.000
L1.Niederösterreich 0.192742 0.085247 2.261 0.024
L1.Oberösterreich 0.123453 0.084100 1.468 0.142
L1.Salzburg 0.258086 0.043256 5.966 0.000
L1.Steiermark 0.036189 0.057090 0.634 0.526
L1.Tirol 0.101474 0.046101 2.201 0.028
L1.Vorarlberg -0.067964 0.040673 -1.671 0.095
L1.Wien 0.016711 0.074877 0.223 0.823
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054320 0.144066 0.377 0.706
L1.Burgenland -0.037707 0.087761 -0.430 0.667
L1.Kärnten 0.042005 0.045850 0.916 0.360
L1.Niederösterreich -0.204465 0.183328 -1.115 0.265
L1.Oberösterreich 0.455443 0.180862 2.518 0.012
L1.Salzburg 0.283223 0.093024 3.045 0.002
L1.Steiermark 0.112768 0.122775 0.918 0.358
L1.Tirol 0.305531 0.099143 3.082 0.002
L1.Vorarlberg 0.026533 0.087470 0.303 0.762
L1.Wien -0.028667 0.161027 -0.178 0.859
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197749 0.034221 5.779 0.000
L1.Burgenland 0.089053 0.020846 4.272 0.000
L1.Kärnten -0.007095 0.010891 -0.651 0.515
L1.Niederösterreich 0.241817 0.043547 5.553 0.000
L1.Oberösterreich 0.159689 0.042961 3.717 0.000
L1.Salzburg 0.040099 0.022097 1.815 0.070
L1.Steiermark 0.026918 0.029164 0.923 0.356
L1.Tirol 0.081294 0.023550 3.452 0.001
L1.Vorarlberg 0.054096 0.020777 2.604 0.009
L1.Wien 0.118591 0.038250 3.100 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118279 0.034215 3.457 0.001
L1.Burgenland 0.043090 0.020843 2.067 0.039
L1.Kärnten -0.012952 0.010889 -1.189 0.234
L1.Niederösterreich 0.172180 0.043539 3.955 0.000
L1.Oberösterreich 0.335978 0.042953 7.822 0.000
L1.Salzburg 0.099890 0.022093 4.521 0.000
L1.Steiermark 0.111260 0.029158 3.816 0.000
L1.Tirol 0.089264 0.023546 3.791 0.000
L1.Vorarlberg 0.060426 0.020774 2.909 0.004
L1.Wien -0.017643 0.038243 -0.461 0.645
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126584 0.064269 1.970 0.049
L1.Burgenland -0.044306 0.039151 -1.132 0.258
L1.Kärnten -0.045303 0.020454 -2.215 0.027
L1.Niederösterreich 0.135372 0.081784 1.655 0.098
L1.Oberösterreich 0.160502 0.080684 1.989 0.047
L1.Salzburg 0.284972 0.041499 6.867 0.000
L1.Steiermark 0.058145 0.054771 1.062 0.288
L1.Tirol 0.157978 0.044228 3.572 0.000
L1.Vorarlberg 0.097281 0.039021 2.493 0.013
L1.Wien 0.071900 0.071835 1.001 0.317
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.076893 0.050156 1.533 0.125
L1.Burgenland 0.025825 0.030553 0.845 0.398
L1.Kärnten 0.053312 0.015962 3.340 0.001
L1.Niederösterreich 0.190413 0.063825 2.983 0.003
L1.Oberösterreich 0.331102 0.062966 5.258 0.000
L1.Salzburg 0.034968 0.032386 1.080 0.280
L1.Steiermark 0.007902 0.042743 0.185 0.853
L1.Tirol 0.118666 0.034516 3.438 0.001
L1.Vorarlberg 0.065712 0.030452 2.158 0.031
L1.Wien 0.097301 0.056061 1.736 0.083
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173979 0.060474 2.877 0.004
L1.Burgenland 0.005113 0.036839 0.139 0.890
L1.Kärnten -0.065814 0.019246 -3.420 0.001
L1.Niederösterreich -0.107892 0.076955 -1.402 0.161
L1.Oberösterreich 0.207040 0.075920 2.727 0.006
L1.Salzburg 0.054614 0.039049 1.399 0.162
L1.Steiermark 0.246942 0.051537 4.792 0.000
L1.Tirol 0.500473 0.041617 12.026 0.000
L1.Vorarlberg 0.064202 0.036717 1.749 0.080
L1.Wien -0.075571 0.067594 -1.118 0.264
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160931 0.067093 2.399 0.016
L1.Burgenland -0.001950 0.040871 -0.048 0.962
L1.Kärnten 0.062981 0.021353 2.950 0.003
L1.Niederösterreich 0.166695 0.085377 1.952 0.051
L1.Oberösterreich -0.056416 0.084229 -0.670 0.503
L1.Salzburg 0.208464 0.043322 4.812 0.000
L1.Steiermark 0.138443 0.057177 2.421 0.015
L1.Tirol 0.055647 0.046172 1.205 0.228
L1.Vorarlberg 0.146958 0.040735 3.608 0.000
L1.Wien 0.121456 0.074992 1.620 0.105
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.389958 0.039452 9.884 0.000
L1.Burgenland -0.003272 0.024033 -0.136 0.892
L1.Kärnten -0.020844 0.012556 -1.660 0.097
L1.Niederösterreich 0.202926 0.050203 4.042 0.000
L1.Oberösterreich 0.228471 0.049528 4.613 0.000
L1.Salzburg 0.037017 0.025474 1.453 0.146
L1.Steiermark -0.015701 0.033621 -0.467 0.640
L1.Tirol 0.089546 0.027150 3.298 0.001
L1.Vorarlberg 0.050896 0.023953 2.125 0.034
L1.Wien 0.043908 0.044096 0.996 0.319
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036597 0.104183 0.167588 0.137684 0.096454 0.079946 0.032044 0.209774
Kärnten 0.036597 1.000000 -0.027308 0.131153 0.048628 0.084719 0.443781 -0.067116 0.089289
Niederösterreich 0.104183 -0.027308 1.000000 0.312153 0.118797 0.271995 0.065432 0.152259 0.291018
Oberösterreich 0.167588 0.131153 0.312153 1.000000 0.212150 0.294791 0.166264 0.136339 0.237742
Salzburg 0.137684 0.048628 0.118797 0.212150 1.000000 0.122356 0.091433 0.104879 0.123822
Steiermark 0.096454 0.084719 0.271995 0.294791 0.122356 1.000000 0.133190 0.106225 0.035168
Tirol 0.079946 0.443781 0.065432 0.166264 0.091433 0.133190 1.000000 0.063384 0.150962
Vorarlberg 0.032044 -0.067116 0.152259 0.136339 0.104879 0.106225 0.063384 1.000000 -0.004375
Wien 0.209774 0.089289 0.291018 0.237742 0.123822 0.035168 0.150962 -0.004375 1.000000